<template>
	<!-- 采购录单 -->
	<view class="wrap">
		<u-form :model="model1" :rules="rules" ref="uForm" :errorType="errorType">
			<!-- 粘贴识别信息 -->
			<!-- <view class="shibiebox">
				<view style="height: 170px;">
					<textarea maxlength="999999" class="texta" placeholder="粘贴信息自动识别" v-model="pasteText"></textarea>
					<view>
						<view class="seebtn" @click="handlePaste">识别</view>
					</view>
				</view>
			</view>
			<u-form-item :leftIconStyle="{ color: '#888', fontSize: '32rpx' }" left-icon="account" label-width="180"
				:label-position="labelPosition" label="客户名称" prop="customer">
				
				<u-input :border="border" v-model="model1.customer" placeholder="请选择客户"></u-input>
				<u-icon slot="right" name="arrow-right" @click="customerSheetShow = true"></u-icon>
			</u-form-item>

			<u-form-item :leftIconStyle="{ color: '#888', fontSize: '32rpx' }" left-icon="edit-pen" label-width="180"
				:label-position="labelPosition" label="联系人" prop="linkman">
				<u-input :border="border" placeholder="请输入联系人" v-model="model1.linkman" type="text"></u-input>
			</u-form-item>

			<u-form-item :rightIconStyle="{ color: '#888', fontSize: '32rpx' }" right-icon="phone"
				:label-position="labelPosition" label="手机号码" prop="phone" label-width="150">
				<u-input :border="border" placeholder="请输入手机号" v-model="model1.phone" type="number"></u-input>
			</u-form-item>
			

			<u-form-item label-width="180" :label-position="labelPosition" label="交货类型">
				<u-input :border="border" type="select" :select-open="typelistShow" v-model="typelist[typelistIndex].label"
					placeholder="交货类型" @click="typelistShow = true"></u-input>
			</u-form-item>

			<u-picker mode="region" v-model="showRegion" :params="params" :area-code='["45", "4501", "450102"]'
				@confirm="selectRegion"></u-picker>
			<u-form-item :label-position="labelPosition" label-width=" 100px" label="地址" prop="city" borderBottom
				ref="item1" @tap="showRegions">

				<u-input style="text-align: right;" v-model="model1.city" disabled disabledColor="#ffffff"
					placeholder="请输入地址"></u-input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>


			<u-form-item :leftIconStyle="{ color: '#888', fontSize: '32rpx' }" :label-position="labelPosition" label="详细地址"
				prop="address">
				<u-input type="textarea" :border="border" placeholder="详细地址" v-model="model1.address" />
			</u-form-item>


			<u-form-item :label-position="labelPosition" label-width=" 100px" label="类型" prop="sex" borderBottom>
				<u-radio-group v-model="radiovalue1">
					<u-radio v-for="( item, index ) in  radiolist1 " :key="index" :name="item.name"
						@change="radioChange(item.name, index)">
						{{ item.name }}
					</u-radio>
				</u-radio-group>
			</u-form-item>
			<template v-if="radiovalue1 == '锂电池'">
				<u-form-item :label-position="labelPosition" :leftIconStyle="{ color: '#888', fontSize: '32rpx' }"
					label-width=" 100px" label="容量" prop="load" borderBottom ref="item1">
					<u-input v-model="model1.load" placeholder="请输入容量"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" :leftIconStyle="{ color: '#888', fontSize: '32rpx' }"
					label-width=" 100px" label="车型" prop="model" borderBottom ref="item1">
					<u-input v-model="model1.model" placeholder="请输入车型"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" :leftIconStyle="{ color: '#888', fontSize: '32rpx' }"
					label-width=" 100px" label="保护板" prop="proboard" borderBottom ref="item1">
					<u-input v-model="model1.proboard" placeholder="请输入保护板"></u-input>
				</u-form-item>
			</template>

			<template v-if="radiovalue1 == '无三大件定制'">
				<u-form-item :label-position="labelPosition" :leftIconStyle="{ color: '#888', fontSize: '32rpx' }"
					label-width=" 100px" label="减震颜色" prop="jzcolor" borderBottom ref="item1">
					<u-input v-model="model1.jzcolor" placeholder="请输入减震颜色"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" :leftIconStyle="{ color: '#888', fontSize: '32rpx' }"
					label-width=" 100px" label="卡钳颜色" prop="kqcolor" borderBottom ref="item1">
					<u-input v-model="model1.kqcolor" placeholder="请输入卡钳颜色"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" :leftIconStyle="{ color: '#888', fontSize: '32rpx' }"
					label-width=" 100px" label="轮毂颜色" prop="lgcolor" borderBottom ref="item1">
					<u-input v-model="model1.lgcolor" placeholder="请输入轮毂颜色"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" :leftIconStyle="{ color: '#888', fontSize: '32rpx' }"
					label-width=" 100px" label="车壳颜色" prop="ckcolor" borderBottom ref="item1">
					<u-input v-model="model1.ckcolor" placeholder="请输入车壳颜色"></u-input>
				</u-form-item>
			</template>

			<template v-if="radiovalue1 == '其他'">
				
				<u-form-item borderBottom v-for="( item, index ) in  model1.goods " :key="index">
					<view class="flex justify-between">
						<view class="goodsImg">
							<img src="/static/logo.png" alt="">
						</view>
						<view class="flex flex-direction">
							<view style="width: 180px;" class="text-lg text-bold text-cut">{{ item.name }}</view>
							<view class="text-gray">{{ item.hh }}</view>
							<view class="text-gray">{{ item.gg }}</view>
						</view>
						<view class="flex flex-direction">
							<view class="text-lg text-bold">{{ item.prize }}</view>
							<view class="text-gray">{{ item.danwei }}</view>
							<view class="text-gray">{{ item.num }}</view>
						</view>
						<view>
							<u-icon @click="openDeleteGoods(index)" color="red" size="20px"
								name="close-circle-fill"></u-icon>
						</view>
					</view>
				</u-form-item>
			</template> -->
			<!-- <view class="shibiebox">
				<view style="height: 170px;">
					<textarea maxlength="999999" class="texta" placeholder="粘贴信息自动识别" v-model="pasteText"></textarea>
				</view>
			</view> -->
			<u-form-item :label-position="labelPosition" label="订单信息" prop="remark">
				<view class="texta">
					<u-input type="textarea" :border="border" placeholder="请填写信息" v-model="model1.remark" />
				</view>
			</u-form-item>
			<u-form-item v-if="dinjing2 == 0" :label-position="labelPosition" label-width=" 100px" label="定金" prop="deposit"
				borderBottom ref="item1">
				<u-input v-model="model1.deposit" placeholder="请输入定金"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" borderBottom label-width="90px" label="应付金额" prop="money">
				<u-input v-model="model1.money" placeholder="请输入应付金额"></u-input>

			</u-form-item>

			<u-form-item :label-position="labelPosition" label-width="240px" label="请选择生产人员" prop="producer" borderBottom
				ref="item1">
				<u-input @click="showProducer = true" placeholder="请选择生产人员" disabled v-model="model1.producer"
					disabledColor="#ffffff"></u-input>

				<u-icon @click="showProducer = true" slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-picker @confirm="selectProducer()" @cancel="showProducer = false" mode="selector" v-model="showProducer"
				:range="scmancolumns" range-key="nickname"></u-picker>

			<u-form-item v-if="showscmancolumns">
				<view class="producePerson">
					<view>
						<u-avatar :src="scmancolumns[chooseScman].avatar"></u-avatar>
					</view>
					<view>
						{{ scmancolumns[chooseScman].nickname }}
					</view>
					<view>
						电话：{{ scmancolumns[chooseScman].mobile }}
					</view>
				</view>
			</u-form-item>

			<u-form-item borderBottom label-width="90px" label="付款方式">
				<view class="flex flex-direction text-align-right">
					<view class="flex" style="gap: 20px;">

						<u-radio-group v-model="dinjingValue1">
							<u-radio @change="radiodinjing(item.name, index)" v-for="(item, index) in dinjing" :key="index"
								:name="item.name" :disabled="item.disabled">
								{{ item.name }}
							</u-radio>
						</u-radio-group>
					</view>
					<view class="text-xs text-gray">定金请注意收款金额<text class="text-red">*</text> </view>
				</view>
			</u-form-item>
			<u-form-item borderBottom label-width="90px" label="邮寄方式">
				<view class="flex flex-direction text-align-right">
					<view class="flex" style="gap: 20px;">


						<u-radio-group v-model="youjiValue1">
							<u-radio @change="radioyouji(item.name, index)" v-for="(item, index) in youji" :key="index"
								:name="item.name" :disabled="item.disabled">
								{{ item.name }}
							</u-radio>
						</u-radio-group>
					</view>
					<view class="text-xs text-gray">请注意是否包邮<text class="text-red">*</text> </view>
				</view>
			</u-form-item>



			<u-form-item :label-position="labelPosition" label="上传定金图片" label-width="150" v-if="dinjing2 == 0">
				<cl-upload v-model="imagelist" :action="uploadUrl" @onSuccess="onSuccess"></cl-upload>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="上传全款图片" label-width="150" v-else>
				<cl-upload v-model="imagelist" :action="uploadUrl" @onSuccess="onSuccess"></cl-upload>
			</u-form-item>







			<view class="mt20">
				<u-section class="mb12" :title="'应付金额(价税合计)￥ ' + totalMoney" :right="false" :show-line="false"></u-section>
			</view>

			<view class="mt20">
				<u-button type="success" :ripple="true" :plain="true" shape="circle" @click="submitForm">提交</u-button>
			</view>
		</u-form>

		<u-calendar max-date="2050-01-01" v-model="delivery_timeSheetShow" mode="date" @change="delivery_timeChange"
			toolTip='交货时间'></u-calendar>
		<u-select mode="single-column" :list="customerSelectList" v-model="customerSheetShow"
			@confirm="selectConfirm"></u-select>

		<u-select mode="single-column" :list="typelist" v-model="typelistShow" @confirm="selecttypelistConfirm"></u-select>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
var _this;
import AddressParse from '@/components/xghc-addrress/zh-address-parse.min.js';
export default {
	data() {
		return {
			isSubmitting: false,
			uploadUrl: '',
			jiaohuotype: 1,
			producePerson: '',
			dinjing2: 0,
			zuzhuang2: 0,
			youji2: 0,
			radiovalue2: 0,
			zuzhuang: [{
				name: '不组装',
				disabled: false
			},
			{
				name: '组装',
				disabled: false
			}],
			dinjing: [{
				name: '定金+尾款',
				disabled: false
			},
			{
				name: '全款',
				disabled: false
			}
			],
			youji: [{
				name: '到付',
				disabled: false
			},
			{
				name: '包邮',
				disabled: false
			}
			],
			showscmancolumns: false,
			scmancolumns: [],
			imagelist: [],
			uploadimagelist: [],
			openOrderForm: {
				earnest_money: '',
				customer_name: '',
				linkman: '',
				phone: '',
				delivery_time: '',
				type: '',
				product_id: '',
				product_price: '',
				product_nums: '',
				product_remarks: '',
				product_unit: '',
				product_wait_nums: '',
				product_length: '',
				wait_nums: '',
				total_nums: '',
				city: '',
				address: '',
				rate: '',
				real_money: '',
				theory_money: '',
				remark: '',
				is_assemble: '',
				earnest_money_imgs: '',
				full_payment: '',
				full_payment_imgs: '',
				payment_status: '',
				balance_payment: '',
				balance_payment_imgs: '',
				mailing_type: '',
				sell_type: '',
			},
			model1: {
				customer: '',
				remark: '',
				city: '',

				linkman: '',
				address: '',
				sex: '',
				data: '2024-01-24',
				name: '', //客户名称
				phone: '', //电话
				remark: '',
				address: '', //地址
				describe: '', //描述
				producer: '', //生产人

				isAssemble: false, //true组装 false不组装
				ismoney: false, //true全款 false定金
				post: false, //true包邮 false到付
				money: '', //金额
				imgurl: '', //转款截图
				notes: '', //备注


				// 锂电的情况
				load: '', //容量
				model: '', //车型
				proboard: '', //保护板
				deposit: '', //定金
				delivery_time: '',
				//无三大定制化的情况
				jzcolor: '', //减震颜色
				kqcolor: '', //卡钳颜色
				lgcolor: '', //轮毂颜色
				ckcolor: '', //车壳颜色
			},
			params: {
				year: true,
				month: true,
				day: true,
				hour: true,
				minute: true,
				second: true,
				province: true,
				city: true,
				area: true,
				timestamp: true
			},
			dateparams: {
				year: true,
				month: true,
				day: true,
				hour: false,
				minute: false,
				second: false
			},
			pasteText: '',
			showRegion: false,
			showSex: false, //是否显示性别选择器
			showData: false, //是否显示日期选择器
			showProducer: false, //是否显示生产人员选择器
			extractedInfo: {
				'名字': '',
				'号码': '',
				'地址': '',
				'容量': '',
				'车型': '',
				'保护板': '',
				'定金': '',
				'减震颜色': '',
				'卡钳颜色': '',
				'轮毂颜色': '',
				'车壳颜色': ''
			},
			//当前的类型
			type: '无三大件定制',


			columns: ['王师傅18878787878', '刘师傅18878787878', '吴师傅18878787878'],


			radiolist1: [{
				name: '无三大件定制',
				disabled: false
			},
			{
				name: '锂电池',
				disabled: false
			},
			{
				name: '其他',
				disabled: false
			},
			],
			// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
			radiovalue1: '无三大件定制',
			zuzhuangValue1: '不组装',
			dinjingValue1: '定金+尾款',
			youjiValue1: '到付',
			model: {
				customer: '',
				name: '',
				linkman: '',
				address: '',
				city: '',
				remark: '',
				phone: '',
				telephone: '',
				type: '',
				delivery_time: '', //交货日期
				rate: '16',

			},

			radio: '',
			switchVal: false,
			rules: {
				remark: [{
					required: true,
					message: '请输入订单信息',
					trigger: 'blur',
				}],
				jhdate: [{
					required: true,
					message: '请输入交货日期',
					trigger: 'blur',
				}],
				deposit: [{
					required: true,
					message: '请输入定金',
					trigger: 'blur',
				}],
				producer: [{
					required: true,
					message: '请选择生产人员',
					trigger: ['blur', 'change'],
				}],
				money: [{
					required: true,
					message: '请输入应付金额',
					trigger: 'blur',
				}],
				photo: [{
					required: true,
					message: '请上传截图',
					trigger: 'blur',
				}],
				supplier: [{
					required: true,
					message: '请输入交货方式',
					trigger: 'blur',
				}],
				rate: [{
					required: true,
					message: '请输入税率',
					trigger: 'blur',
				}],
				name: [{
					required: true,
					message: '请输入名称',
					trigger: 'blur',
				}],
				linkman: [{
					required: true,
					message: '请输入联系人',
					trigger: 'blur',
				}],
				city: [{
					required: true,
					message: '请选择地区',
					trigger: 'change',
				}],
				address: [{
					required: true,
					message: '请选择地区',
					trigger: 'change',
				}],
				type: [{
					required: true,
					message: '请选择仓库类型',
					trigger: 'change',
				}],
				phone: [{
					required: true,
					message: '请输入手机号',
					trigger: ['change', 'blur'],
				},
				{
					validator: (rule, value, callback) => {
						// 调用uView自带的js验证规则，详见：https://www.uviewui.com/js/test.html
						return this.$u.test.mobile(value);
					},
					message: '手机号码不正确',
					// 触发器可以同时用blur和change，二者之间用英文逗号隔开
					trigger: ['change', 'blur'],
				}
				],
				telephone: [{
					required: true,
					message: '请输入座机号码',
					trigger: ['change', 'blur'],
				},
				{
					validator: (rule, value, callback) => {
						// 调用uView自带的js验证规则，详见：https://www.uviewui.com/js/test.html
						return this.$u.test.mobile(value);
					},
					message: '座机号码不正确',
					// 触发器可以同时用blur和change，二者之间用英文逗号隔开
					trigger: ['change', 'blur'],
				}
				],
			},
			pickerShow: false,
			border: false,
			errorType: ['message'],
			labelPosition: 'top',
			unitList: [],
			unitListShow: false,
			chooseScman: '',
			customerSheetShow: false,
			customerList: {}, //供应商列表
			customerSelectList: [], //待选供应商列表
			customerSelectindex: 0, //选择的供应商索引
			userAddress: {
				real_name: "",
				phone: "",
				region: "",
				detail: "",
			}, //地址详情
			delivery_timeSheetShow: false,
			delivery_timetime: null,

			/* 卡片 订单列表 */
			commodityList: [],

			userInfoForm: {
				shock_absorber_color: '',
				productionperson: '',
				earnest_money: '',
				customer_name: '',
				linkman: '',
				phone: '',
				delivery_time: '',
				type: '',
				product_id: '',
				product_price: '',
				product_nums: '',
				product_remarks: '',
				product_unit: '',
				product_wait_nums: '',
				product_length: '',
				wait_nums: '',
				total_nums: '',
				city: '',
				address: '',
				rate: '',
				real_money: '',
				theory_money: '',
				remark: '',
				is_assemble: '',
				earnest_money_imgs: '',
				full_payment: '',
				full_payment_imgs: '',
				payment_status: '',
				balance_payment: '',
				balance_payment_imgs: '',
				mailing_type: '',
				sell_type: '',
			},
			imageUrl: '',

			/* 类型 交货方式:1=买家自提,2=卖方发货,3=代发*/
			typelistShow: false,
			typelist: [{
				label: '买家自提',
				value: 0,
			}, {
				label: '卖家发货',
				value: 1,
			}, {
				label: '代发',
				value: 2,
			}],
			typelistIndex: 0,
		}

	},
	computed: {
		totalMoney() {

			if (this.dinjing2 == 0) {
				return Number(this.model1.money) + Number(this.model1.deposit)
			} else {
				return this.model1.money
			}
			// var totalMoney = 0

			// for (let i = 0; i < this.commodityList.length; i++) {
			// 	totalMoney += this.commodityList[i].num * this.commodityList[i].money
			// }
			// totalMoney = totalMoney + totalMoney * _this.model.rate / 100
			// return totalMoney.toFixed(2);
		}
	},
	onShow() {
		var list = uni.getStorageSync('commodityList');
		if (list) {
			for (let i = 0; i < list.length; i++) {
				let t = true;
				for (let j = 0; j < _this.commodityList.length; j++) {
					if (_this.commodityList[j].id == list[i].id) {
						t = false;
						continue;
					}
				}
				if (t) {
					t = true;
					_this.commodityList.push(list[i])
				}
			}
		}

		uni.removeStorageSync('commodityList')

	},
	onLoad() {
		_this = this;
		_this.getcustomerList()
		_this.getscman()
		_this.uploadUrl = _this.api_root + 'api/common/upload'
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	methods: {
		getscman() {
			_this._post_form('/api/ykjp/sell/Sell/getscman', {}, (result) => {
				_this.scmancolumns = result.data.data
				console.log('_this.scmancolumns: ', _this.scmancolumns)
				_this.columns = result.data.data.nickname
				console.log('_this.columns: ', _this.columns)
			});
		},
		onremovechoose(index, list) {
			this.imageUrl = null;
		},
		onchoosecomplete(list) {
			this.imageUrl = list[0].url;
		},

		onSuccess(reslut) {
			this.uploadimagelist.push(reslut.data.url)
			// 把服务端返回的图片地址添加到list中与组件数据同步
			this.imagelist.push(_this.api_root + reslut.data.url)

		},
		sendImage() {
			uni.uploadFile({
				url: _this.api_root + 'api/common/upload',
				filePath: _this.imageUrl,
				name: 'file',
				success: function (res) {
					var e = JSON.parse(res.data)
					console.log('%c [ e ]-666', 'font-size:13px; background:pink; color:#bf2c9f;', e)
					// if (e.code == 1) {
					// _this.model.prop[0].title = _this.model.name
					// _this._post_form('/api/ykjp/product/product/add', {
					// 	name:_this.model.commodity,
					// 	product_type_id:_this.model.product_type_id,
					// 	specification:_this.model.specification,
					// 	sku:_this.model.sku,
					// 	prop:JSON.stringify(_this.model.prop),
					// 	remark:_this.model.intro,
					// 	product_unit_id:_this.model.product_unit_id,
					// 	unit:_this.model.unit,
					// 	image:e.data.url,
					// }, (result) => {
					// 	_this.$refs.uToast.show({
					// 		title: '添加成功',
					// 		type: 'success',
					// 		back: true
					// 	})
					// });
					// }
				},
				complete: function (res) { }
			});
		},
		showRegions() {
			this.showRegion = true
			console.log('this.showRegion: ', this.showRegion)
		},
		identify() {
			const options = {
				type: 0, // 哪种方式解析，0：正则，1：树查找
				textFilter: [], // 预清洗的字段
				nameMaxLength: 4, // 查找最大的中文名字长度
			}
			if (!!this.model1.address) {
				const parseResult = AddressParse(this.model1.address, options)
				// console.log(parseResult);
				this.userAddress.real_name = parseResult.name;
				this.userAddress.phone = parseResult.phone;
				this.userAddress.detail = parseResult.detail;
				this.userAddress.region = parseResult.province + '/' + parseResult.city + '/' + parseResult.area;

			}
			this.model1.city = this.userAddress.region
			this.model1.address = this.userAddress.detail
			console.log('userAddress: ', this.userAddress)
		},
		submitForm() {
			if (_this.isSubmitting) {
				console.log('请勿频繁点击');
				return;
			}

			_this.$refs.uForm.validate(valid => {
				if (valid) {
					// 设置正在提交标志为 true
					_this.isSubmitting = true;

					// 提交订单
					_this.openOrder();

					// 3 秒后重置提交标志，已转移到openOrder
					// setTimeout(() => {
					// 	_this.isSubmitting = false;
					// }, 3000);
				} else {
					console.log('验证失败');
				}
			});
		},
		getUsername(event) {

			// const clipboardData = event.clipboardData || window.clipboardData;

			// const pastedText = clipboardData.getData('text');
			const pastedText = this.model1.remark;
			const fields = ['名字'];

			// 按照换行符分割粘贴的文本
			const lines = pastedText.split('\n');
			console.log('lines: ', lines)

			// 对每一行进行处理
			lines.forEach(line => {
				// 对每个字段进行匹配
				fields.forEach(field => {
					const regExp = new RegExp(`${field}：(.*?)$`);
					const match = line.match(regExp);
					if (match && match[1]) {
						this.extractedInfo[field] = match[1].trim();
					}
				});
			});
			console.log('321', this.extractedInfo)

			this.model1.linkman = this.extractedInfo['名字']
			this.model1.customer = this.extractedInfo['名字']

		},
		openOrder() {
			// 获取用户名字
			_this.getUsername()
			// 基本信息
			_this.userInfoForm.customer_name = _this.model1.customer
			_this.userInfoForm.linkman = _this.model1.linkman
			_this.userInfoForm.phone = _this.model1.phone
			_this.userInfoForm.delivery_time = _this.model.delivery_time
			// _this.userInfoForm.type = _this.model1.type
			_this.userInfoForm.city = _this.model1.city
			_this.userInfoForm.address = _this.model1.address

			// 选择类型
			_this.userInfoForm.sell_type = _this.radiovalue2

			// 无三大件
			_this.userInfoForm.shock_absorber_color = _this.model1.jzcolor
			_this.userInfoForm.caliper_color = _this.model1.kqcolor
			_this.userInfoForm.wheel_hub_color = _this.model1.lgcolor
			_this.userInfoForm.car_body_color = _this.model1.ckcolor

			// 锂电池
			_this.userInfoForm.capacity = _this.model1.load
			_this.userInfoForm.car_model = _this.model1.model
			_this.userInfoForm.protective_plate = _this.model1.proboard


			_this.userInfoForm.earnest_money = _this.model1.deposit


			// 单选
			_this.userInfoForm.is_assemble = _this.zuzhuang2
			_this.userInfoForm.payment_status = _this.dinjing2
			// _this.userInfoForm.mailing_type = _this.model1.post
			_this.userInfoForm.mailing_type = _this.youji2

			// 应付金额
			_this.userInfoForm.real_money = _this.model1.money

			// 付款截图
			if (_this.dinjing2 == 0) {
				_this.userInfoForm.earnest_money_imgs = _this.uploadimagelist
			} else {
				_this.userInfoForm.full_payment_imgs = _this.uploadimagelist
			}




			_this.userInfoForm.productionperson = _this.producePerson
			// 备注
			_this.userInfoForm.remark = _this.model1.remark

			_this.userInfoForm.type = _this.jiaohuotype


			_this._post_form('api/ykjp/sell/Sell/newAddSell', _this.userInfoForm, (result) => {

				// _this.setData({'sortlist' : result.data.data})
				if (result.code == 1) {
					console.log('321MMM')
					_this.$refs.uToast.show({
						title: '添加成功',
						type: 'success',
						back: true
					})
					// 3 秒后重置提交标志
					setTimeout(() => {
						_this.isSubmitting = false;
					}, 3000);
				} else{
					_this.$refs.uToast.show({
						title: '添加失败',
						type: 'error',
						back: true
					})
				}
			});
		},
		addressConfirm(data) {
			console.log(data);
		},
		showRegions() {
			this.showRegion = true
			console.log('this.showRegion: ', this.showRegion)
		},
		getNowFormatDate() {
			let date = new Date(),
				year = date.getFullYear(), //获取完整的年份(4位)
				month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
				strDate = date.getDate() // 获取当前日(1-31)
			if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
			if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0

			return `${year}-${month}-${strDate}`
		},
		openDeleteGoods(i) {
			const _this = this
			//删除商品弹窗
			uni.showModal({
				title: '提示',
				content: '是否删除商品',
				// #ifdef APP-PLUS
				showCancel: false,
				// #endif
				success: (res) => {
					if (res.confirm) {
						console.log('客户点击确定');
						_this.deleteGoods(i)
					}
				}
			})
		},
		deleteGoods(i) {
			console.log('%c [ i ]-370', 'font-size:13px; background:pink; color:#bf2c9f;', i)
			//删除商品
			this.model1.goods.splice(i, 1)
		},
		//预览图片
		openImg() {
			let imgsArray = this.model1.imgurl.split(',');
			uni.previewImage({
				current: 0,
				urls: imgsArray,
			});
		},
		//删除图片弹窗
		openDeleteImg() {
			const _this = this
			//弹框确认是否删除图片
			uni.showModal({
				title: '提示',
				content: '是否删除转款截图',
				// #ifdef APP-PLUS
				showCancel: false,
				// #endif
				success: (res) => {
					if (res.confirm) {
						console.log('客户点击确定');
						_this.deleteImgUrl()
					}
				}
			})
		},
		//删除图片
		deleteImgUrl() {
			this.model1.imgurl = ''
		},
		//选择图片
		choosePhoto() {
			const _this = this;
			uni.chooseImage({
				count: 1, //最多可以选择的图片张数，默认9
				sourceType: ['album'], //album 从相册选图，camera 使客相机，默认二者都有。如需直接开相机或直接选相册，请只使客一个选项
				sizeType: ['original'], //original 原图，compressed 压缩图，默认二者都有
				success(res) {
					console.log('选择图片完成', res)
					// 调客上传图片的接口
					// _this.uploadPhoto(res.tempFilePaths);
					_this.model1.imgurl = res.tempFilePaths[0]
					console.log('%c [ res.tempFilePaths[0] ]-261',
						'font-size:13px; background:pink; color:#bf2c9f;', res.tempFilePaths[0])
				},
				fail() {
					console.log('失败', err);
				},
				complete() {
					console.log('结束');
				},
			})
		},

		changeMoney(e) {
			console.log('%c [ e ]-904', 'font-size:13px; background:pink; color:#bf2c9f;', e)
			this.model1.ismoney = e
		},
		changePost(e) {
			this.model1.post = e
		},
		changeAb(e) {
			this.model1.isAssemble = e
		},
		selectProducer(e) {
			this.showscmancolumns = true
			this.showProducer = false
			this.chooseScman = e['0']
			let a = this.chooseScman
			this.model1.producer = this.scmancolumns[a].nickname
			this.producePerson = this.scmancolumns[a].id

		},
		selectData(e) {
			this.showData = false;
			this.model1.data = e.year + '-' + e.month + '-' + e.day
			// this.timeValue = timeValue;
			// console.log(timeValue);


		},
		selectRegion(e) {
			console.log('e: ', e)
			this.showRegion = false;
			this.model1.city = e.province.label + '/' + e.city.label + '/' + e.area.label
			console.log('%c [ this.model1.city ]-1046', 'font-size:13px; background:pink; color:#bf2c9f;', this.model1.city)
			// this.timeValue = timeValue;
			// console.log(timeValue);


		},
		sexSelect(e) {
			this.model1.sex = e.name
			this.$refs.uForm.validateField('form.sex')
		},
		radiodinjing(n, num) {

			this.dinjingValue1 = n

			this.dinjing2 = num

		},
		radioyouji(n, num) {

			this.youjiValue1 = n

			this.youji2 = num

		},
		radiozuzhuang(n, num) {

			this.zuzhuangValue1 = n

			this.zuzhuang2 = num

		},
		radioChange(n, num) {

			this.radiovalue1 = n
			this.radiovalue2 = num
		},
		// 文字识别
		handlePaste(event) {

			// const clipboardData = event.clipboardData || window.clipboardData;

			// const pastedText = clipboardData.getData('text');
			const pastedText = this.pasteText;
			const fields = ['名字', '号码', '地址', '容量', '车型', '保护板', '定金', '减震颜色', '卡钳颜色', '轮毂颜色', '车壳颜色'];

			// 按照换行符分割粘贴的文本
			const lines = pastedText.split('\n');
			console.log('lines: ', lines)

			// 对每一行进行处理
			lines.forEach(line => {
				// 对每个字段进行匹配
				fields.forEach(field => {
					const regExp = new RegExp(`${field}：(.*?)$`);
					const match = line.match(regExp);
					if (match && match[1]) {
						this.extractedInfo[field] = match[1].trim();
					}
				});
			});
			console.log('321', this.extractedInfo)

			this.model1.linkman = this.extractedInfo['名字']
			this.model1.customer = this.extractedInfo['名字']
			this.model1.phone = this.extractedInfo['号码']
			this.model1.address = this.extractedInfo['地址']
			this.model1.load = this.extractedInfo['容量']
			this.model1.model = this.extractedInfo['车型']
			this.model1.proboard = this.extractedInfo['保护板']
			this.model1.deposit = this.extractedInfo['定金']
			this.model1.jzcolor = this.extractedInfo['减震颜色']
			this.model1.kqcolor = this.extractedInfo['卡钳颜色']
			this.model1.lgcolor = this.extractedInfo['轮毂颜色']
			this.model1.ckcolor = this.extractedInfo['车壳颜色']


			this.identify()
		},
		getcustomerList() {
			_this._post_form('/api/ykjp/information/basisinfo/customerinfo/index', {}, (result) => {
				_this.customerSelectList = [];
				for (let i = 0; i < result.data.data.length; i++) {
					_this.customerSelectList.push({
						label: result.data.data[i].name,
						value: i,
					})
				}
				_this.setData({
					'customerList': result.data.data
				})
			});
		},
		submit() {
			this.$refs.uForm.validate(valid => {
				if (valid && this.model.delivery_time != '' && _this.commodityList.length >
					0) {
					for (let i = 0; i < _this.commodityList.length; i++) {
						if (!_this.commodityList[i].money || !_this.commodityList[i].num) {
							return this.$refs.uToast.show({
								title: '验证失败',
								type: 'error'
							})
						}
					}

					_this.sendInfo();
				} else {
					this.$refs.uToast.show({
						title: '验证失败',
						type: 'error'
					})
				}
			});
		},
		sendInfo() {
			let data = {};
			data.customer_info_id = _this.customerList[_this.customerSelectindex].id; //客户id
			data.customer_name = _this.customerList[_this.customerSelectindex].name; //客户
			data.linkman = _this.customerList[_this.customerSelectindex].name; //联系人
			data.phone = _this.model.phone; //电话
			data.delivery_time = _this.delivery_timetime; //交货时间
			data.type = _this.typelistIndex + 1; //类型


			let wait_nums = 0;
			let totalMoney, money = 0

			data.product_id = [];
			data.product_price = [];
			data.product_nums = [];
			data.product_remarks = [];
			data.product_unit = [];
			data.product_wait_nums = [];
			data.product_length = _this.commodityList.length;

			for (let i = 0; i < _this.commodityList.length; i++) {
				wait_nums += _this.commodityList[i].num * 1;
				money += _this.commodityList[i].num * _this.commodityList[i].money

				data.product_id.push(_this.commodityList[i].id)
				data.product_price.push(_this.commodityList[i].money)
				data.product_nums.push(_this.commodityList[i].num)
				data.product_remarks.push(_this.commodityList[i].remark)
				data.product_unit.push(_this.commodityList[i].unit)
				data.product_wait_nums.push(_this.commodityList[i].num)
			}

			totalMoney = money + money * _this.model.rate / 100

			data.wait_nums = wait_nums; //未生成录库单数
			data.total_nums = wait_nums; //产品总数

			data.city = _this.customerList[_this.customerSelectindex].city;
			data.address = _this.customerList[_this.customerSelectindex].address;
			data.rate = _this.model.rate; //税率

			data.real_money = money; //金额
			data.theory_money = totalMoney.toFixed(2); //加上税务金额
			data.status = 0;
			data.admin_id = 1;
			data.remark = _this.model.remark;
			data.storage_status = 0;
			console.log(data);
			_this._post_form('/api/ykjp/sell/sell/addSell', data, (result) => {
				_this.$refs.uToast.show({
					title: '添加成功',
					type: 'success'
				})
				setTimeout(function () {
					uni.navigateBack()
				}, 1000);
			});
		},
		// 选择地区回调
		regionConfirm(e) {
			this.model.city = e.province.label + '/' + e.city.label + '/' + e.area.label;
		},
		// 供应商回调
		selectConfirm(e) {
			e.map((val, index) => {
				this.model1.customer = val.label;
				this.customerSelectindex = val.value;

				this.model1.linkman = this.customerList[this.customerSelectindex].contact;
				this.model1.phone = this.customerList[this.customerSelectindex].phone;
				this.model1.address = this.customerList[this.customerSelectindex].address;
			})
		},

		/* 选择类型回调 */
		selecttypelistConfirm(e) {
			e.map((val, index) => {
				this.jiaohuotype = val.value + 1
				console.log('index: ', this.jiaohuotype)
				this.typelistIndex = val.value;

			})
		},
		/* 选择日期回调 */
		delivery_timeChange(e) {
			_this.model1.delivery_time = e.result
			_this.delivery_timetime = _this.toTimeData(e.result) / 1000
		},
		onAddOrder(e) {
			uni.navigateTo({
				url: 'addsell'
			})
		},
		ondelOrder(index) {
			_this.commodityList.splice(index, index + 1)
		}

	}
}
</script>


<style scoped lang="scss">
.producePerson {
	margin-top: 20rpx;
	display: flex;
	align-items: center;
	justify-content: space-around;
}

.text-align-right {
	margin-top: 30rpx;
	width: 100%;
	display: flex;
	align-items: flex-end;
}

.goodsImg {
	width: 50px;
	height: 50px;

	img {
		width: 100%;
		height: 100%;
		background-size: cover;
	}
}

.sumbit {
	width: 100%;
	height: 88px;
	text-align: center;
	color: #fff;
	background: #ffffff;
	display: flex;
	justify-content: center;
	flex-direction: column;
	align-items: center;

	.btn {
		width: 250px;
		height: 40px;
		background-color: #3C9CFF;
		color: #ffffff;
		text-align: center;
		line-height: 40px;
	}
}

.bgup {
	width: 174px;
	height: 300px;
	background: whitesmoke;
	position: relative;

	.guan {
		position: absolute;
		top: -20px;
		right: -20px;

	}

	img {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}
}

.bg {
	text-align: center;
	width: 174px;
	height: 138px;
	background-image: url('');
	background-size: cover;


}

.zhuankuan {
	text-align: center;
}

.box {}

.switchtext {
	line-height: 25px;

}

.seebtn {
	width: 100px;
	height: 40px;
	padding: 4px;
	text-align: center;
	background: #3C9CFF;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	margin-top: 10px;
	border-radius: 4px;

}

.texta {
	min-height: 100px;
	width: 100%;
	background: #F9F9FB;
	padding-top: 20rpx;
	border-radius: 20rpx;
}

.wrap {
	padding: 30rpx;
	background-color: #fff;
}

.title-wrap {
	display: inline-block;
}

.title {
	text-align: left;
	font-size: 28rpx;
	color: $u-content-color;
	margin-top: 20rpx;
}

.ucard {
	background-color: #eaffe5;
}
</style>